package zhr.chapter13.udpMultithreading;

import java.net.DatagramPacket;
import java.net.DatagramSocket;

public class Receiver extends Thread{
    public void run() {
        try {
            DatagramSocket socket =new DatagramSocket(6666);
            byte[] buf=new byte[1024];
            DatagramPacket packet=new DatagramPacket(buf ,buf.length);
            while (true){
                socket.receive(packet);
                String str=new String(packet.getData(),0, packet.getLength())+" from "
                        +packet.getAddress().getHostAddress()+ ":" + packet.getPort();
                System.out.println(str);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

